home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13608 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: ts13-06.upenn.edu!user
  2. From: sbb@eniac.seas.upenn.edu (Steve Bronstein)
  3. Newsgroups: comp.lang.c
  4. Subject: my program has a mind of its own (no really)
  5. Date: Tue, 09 Apr 1996 03:05:37 -0400
  6. Organization: University of Pennsylvania
  7. Message-ID: <sbb-0904960305370001@ts13-06.upenn.edu>
  8. NNTP-Posting-Host: ts13-06.upenn.edu
  9.  
  10. I am writing a program (with cc as compiler) which has a number of arrays,
  11. which I have been verry careful to initialize with values, to avoid
  12. segmentation faults. The main part of the program is a loop beginning with
  13. an fgets statement to read in the next line from a file. Under certain
  14. circumstances, the program returns "Segmentation Fault" just as it reaches
  15. the beginning of this loop. When I put it a printf statement right before
  16. the loop to see how far it actually got, it worked. 
  17.  
  18. printf("something\n");
  19.  
  20. When I removed "something", leaving just
  21.  
  22. printf("\n");
  23.  
  24. it gave me a segmentation fault again. I tried the same tactic at the
  25. beginning of the loop, and found that the program worked with a long word
  26. in the printf statement, but not a short word. Needless to say, I am
  27. slightly bewildered by this behavior, as the printf statement, at least to
  28. my knowledge, has no effect on my arrrays. If anyone has had a similar
  29. experience, or knows what's going on here, I'd be extremely grateful.
  30.  
  31. Thanks,
  32.  
  33. Steve Bronstein
  34. http://www.seas.upenn.edu/~sbb
  35.